package com.macro.cloud.userservice.controller;

import com.macro.cloud.userservice.domain.CommonResult;
import com.macro.cloud.userservice.domain.User;
import com.macro.cloud.userservice.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    private Logger LOGGER = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private UserService userService;

    @PostMapping("/create")
    public CommonResult create(@RequestBody User user) {
        userService.create(user);
        return new CommonResult("操作成功",200);
    }

    @GetMapping("/{id}")
    public CommonResult getUser(@PathVariable Long id) {
        User user = userService.getUser(id);
        LOGGER.info("根据id获取用户的信息，用户的名称为:{}",user.getUsername());
        return new CommonResult(user);
    }

    @GetMapping("/getUserByIds")
    public CommonResult getUserByIds(@RequestParam List<Long> ids) {
        List<User> userList = userService.getUserByIds(ids);
        LOGGER.info("根据ids获取用户的信息列表:",userList);
        return new CommonResult(userList);
    }
}
